import net.minidev.json.JSONObject;

import java.util.Arrays;
import java.util.List;
import java.util.Set;

/**
 * @Author lzc
 * @Date 2022/12/27 14:32
 */
public class Demo2 {
    public static void main(String[] args) {
        JSONObject obj = new JSONObject();
        obj.put("a", 97);
        obj.put("b", 98);
        obj.put("c", 99);
    
        List<String> columns = Arrays.asList("a,c".split(","));
    
        // for循环只能遍历集合, 不能删除集合
        /*for (String key : obj.keySet()) {
            if (!columns.contains(key)) {
                obj.remove(key);
            }
        }*/
        Set<String> keys = obj.keySet();
        
        /*while (it.hasNext()){
            String key = it.next();
            if (!columns.contains(key)) {
                it.remove();
                
            }
        }*/
    
        keys.removeIf(key -> !columns.contains(key));
    
        System.out.println(obj);
    }
}
